# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
        res = []
        treelist = []
        while root or len(treelist) != 0:
            while root:
                treelist.append(root)
                root = root.left
            if len(treelist) > 0:
                root = treelist[-1]
                res.append(root.val)
                treelist = treelist[:-1]
                root = root.right
        return res
